<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ include file="/wesite/view/common/base.jsp" %>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的采购计划</title>
    <%@ include file="/wesite/view/common/common.jsp" %>
</head>
<body>
<div class="shopping-cart">
    <div class="cl"></div>
    <ul class="list">
    </ul>
</div>
<div class="h98"></div>
<div class="check-procurement-bottom">
    <div class="fl">
        <span class="add" onclick="javascript:window.location.href='${ctx}/we/products/${id}'">添加商品</span>
    </div>
    <div class="btn fr">
        <span class="purchase" onclick="buyseled();">一键采购</span>
        <span class="join" onclick="addToCart();">加购物车</span>
    </div>
</div>
</body>
<script src="${ctx }/plugins/artTemplate/dist/template.js"></script>
<script type="text/javascript" src="${webctx}/script/aui-scroll.js"></script>
<script type="text/javascript" src="${webctx}/script/product-list.js"></script>
<script type="text/javascript">
    apiready = function () {
        api.parseTapmode();
    }

    var parms = {
        url: apiroot + "/we/templateProducts/${id}",
        data: {pno: IPageNo}
    }

    var submiting = false;
    function buyseled() {
        if (submiting) {
            return false;
        }
        submiting = true;
        $w.httpRequest({
            url: apiroot + "/we/WeGenerateorder2",
            data: {"type": "panbuy", "data": ${id}},
            ok: function (ret) {
                var ordercode = ret.Data;
                window.location.href = ctx + "/we/order/" + ordercode;
            }, fail: function (ret) {
                if (ret.MsgCode == '101') {
                    var h = "以下商品库存不足：";
                    var list = window.eval(ret.MsgDesc);
                    for (var i = 0; i < list.length; i++) {
                        h += "\r\n" + (i + 1) + "、" + list[i].productname + (list[i].attrname || '');
                    }
                    alert(h);
                } else if (ret.MsgCode == '102') {
                    var h = "以下商品已下架：";
                    var list = window.eval(ret.MsgDesc);
                    for (var i = 0; i < list.length; i++) {
                        h += "\r\n" + (i + 1) + "、" + list[i].productname + (list[i].attrname || '');
                    }
                    alert(h);
                } else if (ret.MsgCode == '103') {
                    var h = "以下商品已不在您的可购范围：";
                    var list = window.eval(ret.MsgDesc);
                    for (var i = 0; i < list.length; i++) {
                        h += "\r\n" + (i + 1) + "、" + list[i].productname + (list[i].attrname || '');
                    }
                    alert(h);
                } else alert(ret.MsgDesc);
                return false;
            }, all: function () {
                submiting = false;
            }
        })
    }
</script>
<script type="text/html" id="productHtml_list">
    {{each list as value i}}
    <li>
        <div class="selectbox"><input type="checkbox" name="productid" value="{{value.id}}"></div>
        <div class="img">
            <a href="{{ctx}}/we/product/{{value.id}}">
                {{if islogin && isuserauth && value.amount <= 0}}
                <div class="not-available-tips">无货</div>
                {{/if}}
                {{if islogin && isuserauth && value.amount > 0 && !value.canbuy}}
                <div class="not-available-tips"></div>
                {{/if}}
                <img src="{{fileserver}}{{value.photo}}" onerror="this.src='{{ctx}}/wesite/images/noimg.jpg'">
            </a>
        </div>
        <div class="con">
            <h3>{{value.productname}} {{value.name}}</h3>
            <div class="data">
                <p>生产厂家：{{value.b_chanjia}}</p>
                <p>规格：{{value.b_guige}}</p>
                <span class="price">
                    {{if !islogin}}
                        <i>登录可见</i>
                    {{else if !isuserauth}}
                        <i>审核通过可见</i>
                    {{else if !value.canbuy && value.amount > 0}}
                        <i>该商品不在销售区域内</i>
                    {{else if islogin && isuserauth}}
                        <i>¥{{value.price}}</i>
                    {{/if}}
                </span>
                <div class="count-box">
                    <i class="sy_minus">-</i>
                    <input class="num focus-auto-select" name="amount" type="number" maxnum="{{value.amount}}"
                           {{if value.amount> 0}}value="{{value.buyamount}}" {{else}} value="0"{{/if}}>
                    <i class="sy_plus">+</i>
                </div>
            </div>
            <div class="cl"></div>
        </div>
    </li>
    {{/each}}
</script>
</html>